package com.d0331;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class StudentCourse {
    long id;
    String name;
    int course1;
    int course2;
    int course3;

    public StudentCourse(long id, String name, int course1, int course2, int course3) {
        this.id = id;
        this.name = name;
        this.course1 = course1;
        this.course2 = course2;
        this.course3 = course3;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getCourse1() {
        return course1;
    }

    public void setCourse1(int course1) {
        this.course1 = course1;
    }

    public int getCourse2() {
        return course2;
    }

    public void setCourse2(int course2) {
        this.course2 = course2;
    }

    public int getCourse3() {
        return course3;
    }

    public void setCourse3(int course3) {
        this.course3 = course3;
    }

    public double average(){
        return (this.course1+this.course2+this.course3)/3;
    }

    @Override
    public String toString() {
        return "学号:"+this.getId()+" "+"姓名："+this.getName()+" "
                +"成绩:"+getCourse1()+" "+getCourse2()+" "+getCourse3()+""
                +"平均成绩："+this.average();
    }

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);//键盘输入数据
        List<String>myList=new ArrayList<>();//创建一个(String)ArrayList列表
        String str=null;
        while(myList.size()<5){
            //将类实例化对象转换为String类型存入列表中
            str=String.valueOf(new StudentCourse(sc.nextLong(),sc.next(),sc.nextInt(),sc.nextInt(),sc.nextInt()));
            myList.add(str);
        }
        try {
            //读取D:\student.txt
            File file =new File("D:\\student.txt");
            //字符输出流
            FileWriter fr=new FileWriter(file);
            BufferedWriter bw=new BufferedWriter(fr);
            //利用增强for循环将列表里的数据写入到文件中
            for (String s:
                    myList) {
                bw.write(s);
                bw.newLine();//另起一行
            }
            bw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
